'use strict';
class checkDataModel {
  static checkDate(result, msg, status) {
    if (typeof result === 'string') {
      [ result, msg ] = [ msg, result ];
    }
    if (typeof result === 'string' && typeof msg === 'string') {
      result = undefined;
    }
    return {
      msg,
      result,
      status,
    };
  }
}

class response extends checkDataModel {
  static success(result, msg = '成功操作') {
    return super.checkDate(result, msg, 200);
  }
  static error(result, msg = '操作错误') {
    return super.checkDate(result, msg, 409);
  }
  static lack(result, msg) {
    result = result ? `参数${result}格式不对或者缺失` : '缺少必填参数';
    return super.checkDate(result, msg, 400);
  }
  static notLogin(result, msg = '请登录后再进行操作') {
    return super.checkDate(result, msg, 401);
  }
  static notFound(result, msg = '请求方式不对或者接口地址不正确') {
    return super.checkDate(result, msg, 404);
  }
  static forbidden(result, msg = '没有权限') {
    return super .checkData(result, msg, 403);
  }
}
module.exports = {
  success: response.success,
  error: response.error,
  lack: response.lack,
  notLogin: response.notLogin,
  notFound: response.notFound,
};
